# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
require_dependency "login_system"

class ApplicationController < ActionController::Base
  include LoginSystem
  layout 'standard'
#  require_dependency "employee"
  helper :all # include all helpers, all the time
  protect_from_forgery :only => [:create, :update, :destroy]

  # Scrub sensitive parameters from your log
  # filter_parameter_logging :password
  
  def prepare_from_date(date_name)
    @from_date = ""
    
    if params[:filter][date_name + "_from(1i)"] == ""
        @from_date += "0000-"
    else
        @from_date += params[:filter][date_name + "_from(1i)"] + "-"
    end
    
    if params[:filter][date_name + "_from(2i)"] == ""
        @from_date += "00-"
    else
        @from_date += params[:filter][date_name + "_from(2i)"].rjust(2, '0') + "-"
    end
    
    if params[:filter][date_name + "_from(3i)"] == ""
        @from_date += "00"
    else
        @from_date += params[:filter][date_name + "_from(3i)"].rjust(2, '0')
    end
	
	@from_date
  end
  
  
  def prepare_to_date(date_name)
    @to_date = ""
	
    if params[:filter][date_name + "_to(1i)"] == ""
        @to_date += "9999-"
    else
        @to_date += params[:filter][date_name + "_to(1i)"] + "-"
    end
    
    if params[:filter][date_name + "_to(2i)"] == ""
        @to_date += "12-"
    else
        @to_date += params[:filter][date_name + "_to(2i)"].rjust(2, '0') + "-"
    end
    
    if params[:filter][date_name + "_to(3i)"] == ""
        @to_date += "31"
    else
        @to_date += params[:filter][date_name + "_to(3i)"].rjust(2, '0') + " 23:59:59"
    end
	
	@to_date
  end
  
end
